***********************************************************************************
***	Replication file for:                                                     	***
*** Braun, S. T. and Stuhler, J. (2024). The Economic Consequences of 			***
***	Being Widowed by War: A Life-Cycle Perspective.	     						***
***																				***
***	Journal of Public Economics                                                 ***
***   							                                                ***
*** Script:		2-allbus-prep-1988.do							   			 	***	
*** Purpose:	data preparation, ALLBUS wave 1988								***
***																				***
*** Tables:		---																***
***	Figures:	---																***
***********************************************************************************

* Preamble (unnecessary when executing run.do)
run "$widowsallbus/scripts/programs/_config.do"

************
* Code begins
************

*** Load corrected data (GESIS patch)
do "$widowsallbus/scripts/ZA1670_v1-0-0_patch.do"


*** Relabel, generate variables

*** Study and interview characteristics

gen interview_year = 1988 
label var interview_year "Year of interview"


*** Norms

** Gender roles

recode v537-v545 (9 0 = .) 

* Note: Here category 3 "Weder noch" counts as not confirming statement

gen d_work_mother_goodrel = 0 if inlist(v537, 3, 4, 5)
replace d_work_mother_goodrel = 1 if inlist(v537, 1, 2)
label var d_work_mother_goodrel "Can working mother have as warm and trusting a relationship with her children as non-working mother?"

gen d_work_wife_harmschild = 0 if inlist(v538, 3, 4, 5)
replace d_work_wife_harmschild = 1 if inlist(v538, 1, 2)
label var d_work_wife_harmschild "Will toddler suffer if mother is working?"

gen d_workwife_famsuffers = 0 if inlist(v539, 3, 4, 5)
replace d_workwife_famsuffers = 1 if inlist(v539, 1, 2)
label var d_workwife_famsuffers "Family life suffer if wife works full-time?"

gen d_workwife_happier = 0 if inlist(v540, 3, 4, 5)
replace d_workwife_happier = 1 if inlist(v540, 1, 2)
label var d_workwife_happier "Wife & family happier if wife works?"

gen d_women_preferhh = 0 if inlist(v541, 3, 4, 5)
replace d_women_preferhh = 1 if inlist(v541, 1, 2)
label var d_women_preferhh "Do most women prefer home & kids over work?"

gen d_housewife_occ = 0 if inlist(v542, 3, 4, 5)
replace d_housewife_occ = 1 if inlist(v542, 1, 2)
label var d_housewife_occ "Is being a housewife equally fulfilling as work?"

gen d_workwife_ind = 0 if inlist(v543, 3, 4, 5)
replace d_workwife_ind = 1 if inlist(v543, 1, 2)
label var d_workwife_ind "Work is best way for women to be independent?"

gen d_work_both_spouse = 0 if inlist(v544, 3, 4, 5)
replace d_work_both_spouse = 1 if inlist(v544, 1, 2)
label var d_work_both_spouse "Both spouses should work and contribute to the household income?"

gen d_task_women_hh = 0 if inlist(v545, 3, 4, 5)
replace d_task_women_hh = 1 if inlist(v545, 1, 2)
label var d_task_women_hh "Main task of women is to care about family and household?"

gen index_groles_work = (d_work_mother_goodrel + (1 - d_work_wife_harmschild) + (1 - d_workwife_famsuffers) + d_workwife_happier + (1 - d_women_preferhh) + (1 - d_housewife_occ) + d_workwife_ind + d_work_both_spouse + (1 - d_task_women_hh)) / 9
label var index_groles_work "Progessive norms about womens' work (0-1)"

foreach x in d_work_wife_harmschild d_workwife_famsuffers d_women_preferhh d_housewife_occ d_task_women_hh{
    gen `x'_r = 1 - `x'
}

egen index_groles_work_v2 = rowmean(d_work_mother_goodrel d_work_wife_harmschild_r d_workwife_famsuffers_r d_workwife_happier d_women_preferhh_r  d_housewife_occ_r d_workwife_ind d_work_both_spouse d_task_women_hh_r) 
label var index_groles_work_v2 "Progessive norms about womens' work (0-1), ignoring missings"

drop d_*_r


** Working women, by kids

recode v547 v548 v549 v550 (8 9 0 = .)

gen women_work_nokids = v547
label var women_work_nokids "Should women not work, work part-time or full-time if they have no kids?"

gen women_work_smallkids = v548
label var women_work_smallkids "Should women not work, work part-time or full-time if they have small kids?"

gen women_work_schoolkids = v549
label var women_work_schoolkids "Should women not work, work part-time or full-time if they have school kids?"


label define womenworklab 1 "full-time" 2 "part-time" 3 "not work" 8 "Can't say"
label val women_work* womenworklab


gen d_women_notwork_nokids 		= (women_work_nokids == 3) if women_work_nokids != .
label var d_women_notwork_nokids "Should women not work if they have no kids?"

gen d_women_notwork_smallkids 	= (women_work_smallkids == 3) if women_work_smallkids != .
label var d_women_notwork_smallkids "Should women not work if they have small kids?"

gen d_women_notwork_schkids 	= (women_work_schoolkids == 3) if women_work_schoolkids != .
label var d_women_notwork_schkids "Should women not work if they have school kids?"



*** Demographic variables

gen d_female = (v153 == 2)
label var d_female "Female?"
tab d_female 

recode v433 (97 99 = .)
gen birth_year = 1988 - v433 /* Interview year minus age at interview */
label var birth_year "Birth year"
tab birth_year  

gen years_schooling = 8 if inlist(v154, 1, 2)
replace years_schooling = 10 if v154 == 3
replace years_schooling = 12 if v154 == 4
replace years_schooling = 13 if v154 == 5
label var years_schooling "Years of schooling"


*** Define variables for marriage history

** Ever married?
recode v44 9 = .
gen d_ever_married = 0 if v44 == 5
replace d_ever_married = 1 if inlist(v44, 1, 2, 3, 4)
label var d_ever_married "Was person ever married?"
tab d_ever_married

** Married before end of WW2
gen d_married_b1945 = 0 if v209 != . & v256 != .
replace d_married_b1945 = 1 if inrange(v209, 2305, 4505) | inrange(v256, 2102, 4505)
label var d_married_b1945 "Was person married before end of WW2?"

** Year first marriage
gen date_marriage1 = .
replace date_marriage1 = v209 if v209 != 0
replace date_marriage1 = v256 if date_marriage1 == . & v256 != 0
label var date_marriage1 "Date of first marriage"

gen year_marriage1 = 1900 + floor(date_marriage1/100)
label var year_marriage1 "Year of first marriage"

drop date_marriage1 

** Did spouse die during the war?

gen d_spouse_died_WW2 = 0 if v211 != .
replace d_spouse_died_WW2 = 1 if inrange(v211,3909,4505) | inrange(v258,3909,4505) | v258==4599 |  inrange(v261,3909,4505)
label var d_spouse_died_WW2 "Did spouse die during WW2"

*** Parents

label define sdegreeflab 1 "low" 2 "medium" 3 "high" 4 "don't know/father unknown"
gen school_degree_father = 1 if inlist(v399, 1, 2)
replace school_degree_father = 2 if v399 == 3
replace school_degree_father = 3 if inlist(v399, 4, 5)
replace school_degree_father = 4 if inlist(v399, 8, 0)
label values school_degree_father sdegreeslab
label var school_degree_father "School degree father"
tab school_degree_father

gen years_schooling_father = 8 if inlist(v399, 1, 2)
replace years_schooling_father = 10 if v399 == 3
replace years_schooling_father = 12 if v399 == 4
replace years_schooling_father = 13 if v399 == 5
label var years_schooling_father "Years of schooling father"

gen death_father_WW2 = 0 if inlist(v421, 1, 3) /* father still alive */
recode death_father_WW2 . = 0 if inrange(v422, 1910, 1938) | inrange(v422, 1946, 1988) /* father died before 1939 or after 1945 */
replace death_father_WW2 = 1 if inrange(v422, 1939, 1945)
label var death_father_WW2 "Did father die b/w 1939 and 1945?"

gen death_mother_WW2 = 0 if inlist(v423, 1, 2) /* mother still alive */
recode death_mother_WW2 . = 0 if inrange(v423, 1910, 1938) | inrange(v423, 1946, 1988) /* mother died before 1939 or after 1945 */
replace death_mother_WW2 = 1 if inrange(v423, 1939, 1945)
label var death_mother_WW2 "Did mother die b/w 1939 and 1945?"

gen death_mother_b1945 = death_mother_WW2
recode death_mother_b1945 0 = 1 if inrange(v423, 1910, 1938)
label var death_mother_b1945 "Did mother die in 1945 or earlier?"



*** Order variables

drop v1* v2* v3* v4* v5* v6* v7* v8* v9*

gen ___survey________________ = .
order ___survey________________ interview_year, first

gen ___demography____________ = .
order ___demography____________ birth_year d_female years_schooling, after(interview_year)  

gen ___marriagehist__________ = .
order ___marriagehist__________ d_ever_married year_marriage1 d_married_b1945 d_spouse_died_WW2, after(years_schooling)

gen ___parents_______________ = .
order ___parents_______________ school_degree_father years_schooling_father death_father_WW2 death_mother_WW2 death_mother_b1945, after(d_spouse_died_WW2) 

gen ___norms_pref____________ = .

gen ___gender_roles__________ = .
order ___norms_pref____________ ___gender_roles__________ index_groles_work index_groles_work_v2 women_work_nokids women_work_smallkids women_work_schoolkids d_women_notwork_nokids d_women_notwork_smallkids d_women_notwork_schkids, after(death_mother_b1945)


** Yes/no labels
label define yesno 0 "No" 1 "Yes"
label val d_* yesno  

*** Save

save "$widowsallbus/processed/allbus1988_edit.dta", replace



*** EOF